package com.jurenzhao.partssystem.work.dayli.controller;

import com.jurenzhao.partssystem.work.dayli.entity.WorkMessage;
import com.jurenzhao.partssystem.work.dayli.service.WorkMessageService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/message")
public class WorkMessageController {

    @Resource
    private WorkMessageService workMessageService;

    @RequestMapping("/list1")
    public String messlist(Model model){
        List<WorkMessage> messlist1 = workMessageService.findAll();
        model.addAttribute("messlist1",messlist1);
        return "work/message/list1";
    }

    @RequestMapping("/list/{messId}")
    public String title(Model model,@PathVariable("messId") int messId){
        WorkMessage workMessage = workMessageService.findById(messId);
        model.addAttribute("workMessage",workMessage);
        return "work/message/list";
    }




    @RequestMapping("preadd")
    public String preadd(Model model){
        WorkMessage workMessage = new WorkMessage();
        model.addAttribute("workMessage",workMessage);
        List<WorkMessage> list = workMessageService.findAll();
        model.addAttribute("list",list);
        return "work/message/add";

    }

    @RequestMapping("add")
    public String add(WorkMessage workMessage){
        workMessageService.save(workMessage);
        return "redirect:/message/list";
    }

    @RequestMapping("/preupdate/{messId}")
    public String update(Model model, @PathVariable("messId") int messId){
        WorkMessage workMessage = workMessageService.findById(messId);
        model.addAttribute("workMessage",workMessage);
        List<WorkMessage> list = workMessageService.findAll();
        model.addAttribute("list",list);
        return "work/message/update";
    }


    @RequestMapping("update")
    public String updateSelect(WorkMessage workMessage){
        workMessageService.updateselect(workMessage);
        return "redirect:/message/list";
    }

    @RequestMapping("/delete/{messId}")
    public String delete(@PathVariable("messId") int messId){
        workMessageService.delete(messId);
        return "redirect:/message/list";
    }
}




